package tk.mybatis.springboot.share.util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

/**
 * Created by on 2017/3/1.
 */
@Service
public class RedisUtils{

	@Autowired
    private static StringRedisTemplate stringRedisTemplate;
    
    @Autowired
    private static RedisTemplate<Object, Object> redisTemplate;


    /**
     * 根据指定key获取String
     * @param key
     */
    public static String getStr(String key){
        return stringRedisTemplate.opsForValue().get(key);
    }

    /**
     * 设置Str缓存
     * @param key
     * @param val
     */
    public static void setStr(String key, String val, int expires_in){
    	stringRedisTemplate.opsForValue().set(key,val,expires_in);
    }

    /**
     * 删除指定key
     * @param key
     */
    public static void del(String key){
        stringRedisTemplate.delete(key);
    }

    /**
     * 根据指定o获取Object
     * @param o
     * @return
     */
    public static Object getObj(Object o){
        return redisTemplate.opsForValue().get(o);
    }

    /**
     * 设置obj缓存
     * @param o1
     * @param o2
     */
    public static void setObj(Object o1, Object o2, int expires_in){
    	redisTemplate.opsForValue().set(o1, o2, expires_in);
    }

    /**
     * 删除Obj缓存
     * @param o
     */
    public static void delObj(Object o){
        redisTemplate.delete(o);
    }

}
